﻿using System;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using VIT.Library;
using VIT.Web.UI;
using VIT.Web.Controls;
using VIT.Provider;

namespace VIT.Web.Admin
{
    public partial class Account : VITComponent
    {
        Provider.Account acc;
        protected void Page_Load(object sender, EventArgs e)
        {
            acc = new Provider.Account();
        }

        #region Methods
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
        public DataTable GetData(string SortColumn)
        {
            Provider.Account pracc=new Provider.Account();
            //string litChild = pracc.GetAll(SortColumn, "Administrator").GetAllChildId(Session["userName"].ToString(),"CreateByUser","UserName");
            //return pracc.GetAll(ChildId: litChild).SortTable(Session["userName"].ToString(), columnChange: "UserName", distance: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", columnOrder: SortColumn);
            return pracc.GetAll(ChildId: "Administrator").SortTable(Session["userName"].ToString(), columnIdName: "userName", columnChange: "FullName", columParentName: "CreateByUser", distance: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", columnOrder: SortColumn);
        }

        public void DeleteList(string[] listUsr)
        {
            string[] arrChild = acc.GetAll(ChildId: "Administrator").GetAllChildId(Session["userName"].ToString(), "CreateByUser", "UserName").Split(',');
            List<string> lstChild = arrChild.ToList();

            foreach (string usr in listUsr)
            {
                if(lstChild.Contains(usr))
                    acc.Delete(usr);
            }
        }
        #endregion

        #region Events
        protected void Delete_Click(object sender, EventArgs e)
        {
            string[] check = Request["itemCheckbox"].Split(',');
            DeleteList(check);
        }

        protected void Insert_Click(object sender, EventArgs e)
        {
            TransferComponent("Account", "AccountEdit");
        }

        protected void Pager_PreRender(object sender, EventArgs e)
        {
            ListView.DataBind();
        }
        #endregion
    }
}